#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>

#define DKYTGY 175312

void main(){
    int clientfd;
    struct sockaddr_in remote_addr;
    char buffer[BUFSIZ];
    memset(&remote_addr, 0 , sizeof(remote_addr));
    remote_addr.sin_family=AF_INET;
    remote_addr.sin_addr.s_addr=inet_addr("127.0.0.1");
    remote_addr.sin_port=htons(DKYTGY);

    if((clientfd=socket(PF_INET,SOCK_STREAM,0))<0){
        perror("socket");
    }

    if(connect(clientfd, (struct sockaddr *)&remote_addr, sizeof(struct sockaddr))<0){
        perror("connect");
    }

    int len;
    FILE *fp;
    char path[20];
    gets(path);
    fp=fopen(path, "r");
    char readch;
    int i=0;
    while((readch=fgetc(fp))!=EOF){
        if(i<1024){
            buffer[i]=readch;
            i++;
        }
        else{
            i=0;
            int n=send(clientfd, buffer, 1024, 0);
        }
    }
    fclose(fp);
    if(i!=0)
        send(clientfd, buffer, i, 0);
    long wordscount;
    recv(clientfd, &wordscount, sizeof(long), 0);
    printf("%ld\n", wordscount);
    close(clientfd);
}
